package com.example.statistics.ui.bank

import com.example.statistics.R
import com.example.statistics.bean.Bank
import com.example.statistics.common.BaseLoadingListActivity
import com.example.statistics.net.UrlConfig
import com.jhj.slimadapter.SlimAdapter
import com.jhj.slimadapter.holder.ViewInjector
import org.jetbrains.anko.startActivity

/**
 * 现金银行
 */
class CashBankActivity : BaseLoadingListActivity<Bank>() {

    override val title: String
        get() = "现金银行"

    override val url: String
        get() = UrlConfig.BANK_ACCOUNT_LIST
    override val itemLayoutRes: Int
        get() = R.layout.list_item_single_display

    override fun itemViewConvert(adapter: SlimAdapter, injector: ViewInjector, bean: Bank, position: Int) {
        val text = if (bean.cardNumber.isBlank()) {
            ""
        } else {
            val str = bean.cardNumber.replace(" ", "")
            str.substring(str.length - 4, str.length)
        }
        injector.text(R.id.text_view, bean.bank + text)
            .text(R.id.text_view_right, bean.balance.toString())
            .clicked {
                startActivity<BankFlowListActivity>("accountId" to bean.ID)
            }

    }


}